Skip to content

correct erase/resize function in Vector#13

Open
jxd134 wants to merge 7 commits intozouxiaohang:masterfrom
jxd134:master
Open

correct erase/resize function in Vector#13
jxd134 wants to merge 7 commits intozouxiaohang:masterfrom
jxd134:master

Conversation

@jxd134
Copy link
Copy Markdown
Contributor

@jxd134 jxd134 commented Mar 14, 2016

Vector:

  1. 按照STL标准,我认为Vector中使用erase函数,需要对对象进行移位操作后,还需进行销毁操作。
    故我对erase(iterator first, iterator last)进行了修改。
  2. erase(iterator position)函数中,原先操作为erase(position,position+1),当
  3. position==finish,finish==end_of_storage情况下,position+1就不妥当了。
  4. 在resize函数中,当n>size()时,需申请n个新空间,而不是申请(LengthOfInsert = n - capacity())个空间。

List:

  1. 在重载==函数中,当数值不相等时可直接return false,不需要跳出循环再进行比较操作。
  2. 如果两个List跳出循环时都是尾端,那么如此操作就会返回true,而不是正确值false。

String

  1. find函数中,如果if (size() - pos < lengthOfS),注意此处size()返回的是size_t,如果size()<pos,则返回的数值极有可能大于 lengthOfS,所以修改为size() < lengthOfS + pos更为保险。
  2. 使用changeVarWhenEuqalNPOS函数进行操作,得到数值需先进行npos==changeVarWhenEuqalNPOS(...)操作

@jxd134 jxd134 changed the title modify erase function in Vector.impl.h correct erase/resize function in Vector.impl.h Mar 14, 2016
@jxd134 jxd134 changed the title correct erase/resize function in Vector.impl.h correct erase/resize function in Vector Mar 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant